package com.hbnu.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao2 {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void addUser() {
        System.out.println("添加用户");
        String sql = "insert into tb_user(username,password,email,phone) values(?,?,?,?)";
        jdbcTemplate.update(sql, "张丽", "123456", "123456@qq.com", "12345678901");
        System.out.println("添加用户成功");
    }

    // 转账
    public void transfer() {
        jdbcTemplate.update("update tb_user set balance = balance + 100 where username = '张三'");
    }


    // 收款
    public void receive() {
        jdbcTemplate.update("update tb_user set balance = balance - 100 where username = '李四'");

    }


}
